<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>公告信息</title>

    <link href="../plugin/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="../plugin/sweetalert-6.6.2/sweetalert2.min.css" rel="stylesheet"/>
    <link href="../plugin/jstree/jstree.min.css" rel="stylesheet">
    <link href="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>

    <script src="../plugin/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="../plugin/sweetalert-6.6.2/sweetalert2.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.formautofill.min.js"></script>
    <script src="../plugin/soul/utils3.js"></script>
    <script src='../base/base.js'></script>
    <script src="../plugin/jquery-3.2.1/jquery.serializejson.js"></script>
    <script src="../plugin/jstree/jstree.min.js"></script>
    <script src="../plugin/wangEditor-3.0.15/wangEditor.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.zh-CN.js"></script>

</head>

<body>
<div class="modal fade" data-backdrop="static" id="announcement_modal_chinese_content">
    <div class="modal-dialog modal-lg ">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>中文公告</b>
                </h4>
            </div>
            <div class="modal-body">
                <div id="announcement_modal_chinese_content_editor"></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="announcement.detail.saveChinese()">保存</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" data-backdrop="static" id="announcement_modal_english_content">
    <div class="modal-dialog modal-lg ">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>英文公告</b>
                </h4>
            </div>
            <div class="modal-body">
                <div id="announcement_modal_english_content_editor"></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="announcement.detail.saveEnglish()">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        var resp = AjaxUtil.isLogin();
        if (!resp) return;
        var module = 'announcement';
        var query = [];
        var toolbar = {
            default: [false, true, true, true],// back;add;edit;remove
            dialog: [60, 2, 9],//对话框参数:模态框宽度(百分比);表单标题宽度;表单输入框宽度
            extra: [
                {
                    name: '中文内容',
                    glyphicon: 'chinese',
                    onclick: 'showChineseContent',
                },{
                    name: '英文内容',
                    glyphicon: 'english',
                    onclick: 'showEnglishContent',
                }
            ]
        };
        var formElement = [{
            action: [false, true],
            type: 'hidden',
            name: 'announcementId',
        }, {
            action: [true, true],
            type: 'text',
            label: '中文标题',
            name: 'chineseTitle',
        }, {
            action: [true, true],
            type: 'text',
            label: '英文标题',
            name: 'englishTitle',
        }, {
            action: [true, true],
            type: 'datetime',
            label: '时间',
            name: 'date',
        }];
        var bootstrapTable = {
            columns: [{
                radio: true
            }, {
                field: 'announcementId',
                title: '公告编号',
                align: 'center',
            }, {
                field: 'chineseTitle',
                title: '中文标题',
                align: 'center',
            }, {
                field: 'englishTitle',
                title: '英文标题',
                align: 'center',
            }, {
                field: 'date',
                title: '时间',
                align: 'center',
                formatter: BootstrapTableUtil.formatter.datetime
            }]
        };
        announcement = SingleTablePageCreateUtil.createInstance(module, null, toolbar, formElement, bootstrapTable);

        announcement.onEditModalShowBefore = function (row) {
            row.date = FormatUtil.formatDateTime(row.date);
            return row;
        };

        announcement.onRemoveSubmitBefore = function (row) {
            row.date = FormatUtil.formatDateTime(row.date);
            return row;
        };

        announcement.showChineseContent = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#announcement_table');
            if (!row) return false;
            announcement.detail.currentId = row.announcementId;
            chineseEditor.txt.html(row.chineseContent || '');
            $('.w-e-text-container').css('height', '500px');
            $('#announcement_modal_chinese_content').modal('show');
        };
        announcement.showEnglishContent = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#announcement_table');
            if (!row) return false;
            announcement.detail.currentId = row.announcementId;
            englishEditor.txt.html(row.englishContent || '');
            $('.w-e-text-container').css('height', '500px');
            $('#announcement_modal_english_content').modal('show');
        };

        announcement.detail = {};
        announcement.detail.currentId = undefined;
        announcement.detail.saveChinese = function () {
            var chineseContent = chineseEditor.txt.html();
            console.log(chineseContent);
            var resp = AjaxUtil.postJson('announcement/editChineseContent', {
                announcementId: announcement.detail.currentId,
                chineseContent: chineseContent
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#announcement_table').bootstrapTable('refresh');
                $('#announcement_modal_chinese_content').modal('hide');
                chineseEditor.txt.html('');
            }

        };
        announcement.detail.saveEnglish = function () {
            var englishContent = englishEditor.txt.html();
            console.log(englishContent);
            var resp = AjaxUtil.postJson('announcement/editEnglishContent', {
                announcementId: announcement.detail.currentId,
                englishContent: englishContent
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#announcement_table').bootstrapTable('refresh');
                $('#announcement_modal_english_content').modal('hide');
                englishEditor.txt.html('');
            }

        };

        var E = window.wangEditor;
        var chineseEditor = new E('#announcement_modal_chinese_content_editor');
        chineseEditor.customConfig.uploadImgServer = 'wangEditor/uploadImages?token=' + BaseConfig.token;
        chineseEditor.customConfig.uploadFileName = 'file';
        chineseEditor.customConfig.uploadImgTimeout = 3 * 60 * 1000;
        chineseEditor.create();

        var englishEditor = new E('#announcement_modal_english_content_editor');
        englishEditor.customConfig.uploadImgServer = 'wangEditor/uploadImages?token=' + BaseConfig.token;
        englishEditor.customConfig.uploadFileName = 'file';
        englishEditor.customConfig.uploadImgTimeout = 3 * 60 * 1000;
        englishEditor.create();
    });
</script>
</html>